Skip to content

Task 01 02 - #10

Open
ArtEnjoyer wants to merge 5 commits into
DafeMipt212:mainfrom
ArtEnjoyer:task_01_02
Open

Task 01 02#10
ArtEnjoyer wants to merge 5 commits into
DafeMipt212:mainfrom
ArtEnjoyer:task_01_02

Conversation

@ArtEnjoyer

Copy link
Copy Markdown

No description provided.

@@ -1,10 +1,11 @@
#include <iostream>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

оставь пустую строчку, так приянто разделять библиотечные инклуды и инклуды из программы

#include "utils.hpp"

#include <stack>
#include <string.h>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

это сишны инклуд, лучше использовать цппшный (cstring)

#include <iostream>
#include <stack>
#include <string>
#include <vector>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

вставь пустую строчку, так будет лучше выглядеть, и после using namespace

using namespace std;
std::vector<std::string> SplitString(const std::string& data) {
return {};
std::vector<std::string> v;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

плохое имя переменной

std::vector<std::string> v;
std::string buff = "";
bool flag = false; //скобки закрыты (или их нет)
// cout << size(data) << endl;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

убери отладку

using namespace std;

std::vector<std::string> SplitString(const std::string& data) {
std::vector<std::string> v;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

плохое название переменной


int Calculate(const std::string& data) {
return 0;
int i = 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

если это индекс для for то обяви его в for
for (int i = 0;....)

return 0;
int i = 0;
int buff_int = 0;
std::string znak = "";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не используй транслит

if (!chisla.empty() and !znak.empty())
rez = chisla[0];
else {
cout << "Error" << endl;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

тут можно просто кинуть исключение, например runtime_error

#include <vector>

int Calculate(const std::string& data);
std::vector<std::string> SplitString(const std::string& data);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

эта функция используется в реализации, ее лучше не вытаскивать в hpp, и оставить в cpp

} else if (data[i] == ')') {
flag = false; //скобки закрыты
}
if (((data[i] != ' ') and (data[i] != '\t')) or (flag == true)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and и or - альтернативные записи операторов && и ||. Вы имеете право их использовать, но мне кажется, что это плохая идея. Причина: они используются крайне редко и будут вызывать удивление у коллег программистов. Кроме того, их поддержка зависит от стандартами языка С++, компилятора и набора ключей для компилятора, а значит код становится менее переносимым. Предлагаю заменить and и or на привычный синтаксис && и ||.

vector<int> chisla;
vector<string> r = SplitString(data);
for (i = 0; i < r.size(); ++i) {
cout << r[i] << endl;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Прошу убрать отладочный код

vector<string> r = SplitString(data);
for (i = 0; i < r.size(); ++i) {
cout << r[i] << endl;
if ((r[i] != "+") and (r[i] != "-") and (r[i] != "*") and (r[i] != "/")) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вы в коде несколько раз проверяете, является ли символ арифметическим оператором, а это длинный if с четырьмя проверками. Возможно, стоит ввести специальную функцию bool IsMathOperator(char c). Это позволит не дублировать код и уменьшит вероятность ошибиться

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants